package com.zuoshen_algorithm;

import java.util.stream.Stream;

/**
 * 冒泡排序(由小到大)
 * 时间复杂度 O(n2)
 * @author xiaohuihui
 */
public class MaoPaoSort {

    public static void main(String[] args) {
        Integer[] num = {4, 1, 2, 7, 8, 5, 3};
        Stream.of(num).forEach(x -> System.out.print(x));
        System.out.println();
        sort(num);
        Stream.of(num).forEach(x -> System.out.print(x));
    }

    public static void sort(Integer[] num) {
        for (int i = 0; i < num.length; i++) {
            for (int j = 0; j < num.length - 1-i; j++) {
                if (num[j] > num[j + 1]) {
                    Util.swap(num,j,j+1);
//                    num[j] = num[j] ^ num[j + 1];
//                    num[j + 1] = num[j] ^ num[j + 1];
//                    num[j] = num[j] ^ num[j + 1];
                }
            }
        }
    }
}
